package com.rk.topN;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 输入数据：
 * 1 1 2020-10-08 12：32：33
 */
public class CountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {

    Text k = new Text();
    LongWritable v = new LongWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        if(line == null || !line.contains("\t")){
            return;
        }
        String[] words = line.split("\t");
        String docId = words[1];
        k.set(docId);
        context.write(k, v);
    }
}
